Followings comprise lexical environment
When object property can be accessible globally.
globalThis, 이 이름은 전역 스코프에서 this가 참조하는 객체이기 때문에 이렇게 지어짐) window는 브라우저에 있고 Web Workers와 Node.js에 없음.self는 Node.js에 없음global은 Node.js에만 있음 👀 참조 [[JavaScript - Host Objects vs Native Objects]]
브라우저에서 globalThis는 전역 객체를 직접적으로 참조하지 않음.
iframe이 사용되는 예시를 통해 살펴보자:
src 값이 바뀌면 새로운 전역 객체가 만들어짐globalThis는 항상 같은 값을 가져야하고, iframe 바깥에서도 확인 가능해야함.firstGlobalThis, 전역 객체의 속성(Array)을 firstArray에 저장하고. iframe의 src 값을 바꾼다.secondGlobalThis, 전역 객체의 속성(Array)를 secondArray에 저장하고 위와 비교해본다.globalThis는 같음. Array는 다름Why?
Window changesWindowProxy forwards object to current Window object브라우저에서 globalThis는 WindowProxy임
Environment for the "outermost" scope
has 2 environmental records for variables:
https://exploringjs.com/deep-js/ch_global-scope.html#lexical-environments